<template>
  <div class="tab-container">
    <el-tabs v-model="activeName" style="margin-top:15px" type="border-card">
      <el-tab-pane v-for="item in tabMapOptions" :key="item.key" :label="item.label" :name="item.key">
        <keep-alive>
          <log-pane v-if="activeName == item.key" :type="item.key" />
        </keep-alive>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import logPane from './components/logPane'

export default {
  name: 'Tab',
  components: { logPane },
  data() {
    return {
      tabMapOptions: [
        { label: '状态码', key: 'status' },
        { label: '响应时间/秒', key: 'requesttime' },
        { label: '日志级别', key: 'level' }
      ],
      activeName: 'status'
    }
  },
  watch: {
    activeName(val) {
      this.$router.push(`${this.$route.path}?tab=${val}`)
    }
  },
  created() {
    const tab = this.$route.query.tab
    if (tab) {
      this.activeName = tab
    }
  },
  methods: {
  }
}
</script>

<style scoped>
  .tab-container {
    margin: 30px;
  }
</style>
